package com.conorroche.taskmanagement;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class AddTag extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_tag);
		
		okButton = (Button) findViewById(R.id.add_tag_ok);
		cancelButton = (Button) findViewById(R.id.add_tag_cancel);
		tagName = (TextView) findViewById(R.id.add_tag_name);
		okButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				storeData();
				finish();
//				DBAdapter db = new DBAdapter(getApplicationContext());
//				db.open();
//				db.getAllTags();
//				db.close();
			}
		});
		cancelButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
	private void storeData(){
		DBAdapter db = new DBAdapter(this);
		db.open();
		db.insertTag(tagName.getText().toString(), "colour", 1);
		db.close();
		Toast.makeText(getApplicationContext(), tagName.getText().toString() + " has been saved", Toast.LENGTH_SHORT).show();
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_add_tag, menu);
		return true;
	}
	Button okButton, cancelButton;
	TextView tagName;
}